home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / prog_c / cuj0696.zip / DWYER.ZIP / GAP.TST / MAXGAPLN.C < prev    next >
C/C++ Source or Header  |  1995-12-21  |  1KB  |  53 lines

  1. /* ============ */
  2. /* maxgapln.c    */
  3. /* ============ */
  4. #include <gapdefs.h>
  5. #include <stdlib.h>
  6. /* ==================================================================== */
  7. /* GetMaxGapLen- Returns Maximum Gap Length For Interval & CellExpect    */
  8. /* ==================================================================== */
  9. int
  10. GetMaxGapLen(double LoLimit, double HiLimit, int CellExpect,
  11.          long MaxNumGaps, int MaxGapLen, double *GapProbs,
  12.          long *GapCtOut)
  13. {
  14.     int     k, m, WhereMax;
  15.     long    NxtGapCt;
  16.     double  MaxGapCt;
  17.  
  18.     *GapCtOut = -1;
  19.     WhereMax  = -1;
  20.  
  21.     for (k = 0; k < MaxGapLen; ++k)
  22.     {
  23.     CalcGapProbs(k+1, LoLimit, HiLimit, GapProbs);
  24.  
  25.     MaxGapCt = -1;
  26.     NxtGapCt = -1;
  27.     for (m = k; m >= 0; --m)
  28.     {
  29.         if (GapProbs[m] == 0)
  30.         {
  31.         continue;
  32.         }
  33.         MaxGapCt =
  34.         __max(MaxGapCt, (double)CellExpect/GapProbs[m]);
  35.     }
  36.     if (MaxGapCt > (double)MaxNumGaps)
  37.     {
  38.         break;
  39.     }
  40.     else
  41.     {
  42.         NxtGapCt = __max((long)MaxGapCt, NxtGapCt);
  43.  
  44.         if (NxtGapCt == (long)MaxGapCt)
  45.         {
  46.             WhereMax = k;
  47.         *GapCtOut = NxtGapCt;
  48.         }
  49.     }
  50.     }
  51.     return (WhereMax + 1);
  52. }
  53.